angular.module('Controller')
.controller('WfUploadModalCtrl', ($scope, urls, activeParam, $localStorage, commonUtil, wfAlert, commonConstant, $http, $uibModalInstance, items)->
    config = items.data
    config = {max: 1} if config == undefined || config.max == undefined
    _.defer(()->
        $("#wfModalFileInput").fileinput({
            language: 'zh',
            maxFileCount: config.max,
            allowedFileExtensions: ['jpg', 'gif', 'png'],
            uploadUrl: urls.backend + urls.imageUploadTo + "/image?token=" + $localStorage['token'],
            uploadAsync: true,
            enctype: 'multipart/form-data',
            showCaption: false
        }).on('fileuploaded', (event, data, id, index)->
            if data.response?.code==0
                $scope.result = data.response?.message
                $uibModalInstance.close($scope.result)
                console.log($scope.result)
        )
    )
    $scope.confirm = ()->
        $uibModalInstance.close($scope.result)
    $scope.cancel = ()->
        $uibModalInstance.dismiss('cancel')
)